package xmlParser;

import java.io.File;
import java.io.IOException;

import ecologylab.xml.ElementState;
import ecologylab.xml.TranslationScope;
import ecologylab.xml.XMLTranslationException;

public class SampleMain
{
//	static final String xml = "<table><records><record><fields name=\"name\" value=\"Bharat\"/><fields name=\"ssn\" value=\"1234567\"/></record><record><fields name=\"name\" value=\"Bharat\"/><fields name=\"ssn\" value=\"1234567\"/></record></records></table>";


	/**
	 * @param args
	 * @throws XMLTranslationException 
	 * @throws IOException 
	 */
	public static void main(String[] args) throws XMLTranslationException, IOException
	{
		Table table = new Table();
		Record sampleRecord1 = new Record();
		Record sampleRecord2 = new Record();
		ColField colField = new ColField();
		ColField colField1 = new ColField();
		colField.setName("name");
		colField.setValue("Bharat");
		colField1.setName("ssn");
		colField1.setValue("1234");
		
		//setting the types of fields in the Table
		ColFieldType colFieldType1 = new ColFieldType("name","String");
		ColFieldType colFieldType2 = new ColFieldType("ssn","Integer");
		table.addfieldType(colFieldType1);
		table.addfieldType(colFieldType2);
		
		sampleRecord1.addField(colField);
		sampleRecord1.addField(colField1);
		table.addRecord(sampleRecord1);
		
		sampleRecord2.addField(colField);
		sampleRecord2.addField(colField1);
		table.addRecord(sampleRecord2);
//		sampleRow.addField("name", "Bharat");
//		sampleRow.addField("ssn","123456789");
		
		File sampleFile = new File("sample.xml");
		File sampleFile1 = new File("sample1.xml");
//		table.writePrettyXML(System.out);
//		table.translateToXML(System.out);
		table.writePrettyXML(sampleFile);
		

		
		final TranslationScope TS = xmlParserTranslationScope.get();
		ElementState newTable = ElementState.translateFromXML(sampleFile,TS);
		System.out.println("debug");
		newTable.writePrettyXML(sampleFile1);
		newTable.writePrettyXML(System.out);
		

	}

}
